Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render raw message #24

Closed
wants to merge 2 commits into from

Conversation

psihachina
Copy link
Contributor

Change:

  • added RenderRawMessage func
  • added Write func for satisfying io.Writer interface

Reason:

For some functions, need to pass io.Writer.
For example:

func DisplayJSONMessagesStream(in io.Reader, out io.Writer, terminalFd uintptr, isTerminal bool, auxCallback func(JSONMessage))

asciicast

It needs for satisfying io.Writer interface.
Copy link
Contributor

@fkorotkov fkorotkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the problem you are trying to solve? How to append bytes without the default \n in the end?

@psihachina
Copy link
Contributor Author

Yes, I would like the ability to send messages without formatting. I tried to wrap log,infof info.Writer, but it didn't help.

type Writer struct {
	logger *echelon.Logger
}

func (w *Writer) Write(p []byte) (n int, err error) {
	w.logger.Infof("%s", p)
	return len(p), err
}

Example:
asciicast

@psihachina psihachina requested a review from fkorotkov October 5, 2022 13:59
fkorotkov added a commit that referenced this pull request Oct 6, 2022
@fkorotkov
Copy link
Contributor

@psihachina, I'm not a big fan of introducing a new message type. PTAL at #25 as an alternative.

@psihachina
Copy link
Contributor Author

@fkorotkov This solution looks better than mine 😄.

@fkorotkov fkorotkov closed this Oct 6, 2022
fkorotkov added a commit that referenced this pull request Oct 6, 2022
* Make Logger comply with io.Writer

Alternative to #24

* Fixed SimpleRenderer

* Format message upon log entry creation

* Reorder fields

* Introduce AsWriter method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants